﻿Filetable format for Pokemon Stadium 2 / Pocket Monster Stadium 3:
0x0	2	#replacement entries
0x2	2	#header entries
0x4	6ea.	replacement table entries; note these are not in sequential order
	0x0	3	offset to data
	0x3	1	total patch files following compressed binary (0 if not present)
	0x4	2	compressed file size
	This table is padded to the nearest word.
...	0x20ea.	header entries
	0x0	1	game version	(1:'Red', 2:'Green', 3:'Blue', 4:'Yellow', 5:'Gold', 6:'Silver', 7:'Crystal')
	0x1	0xF	internal name
	0x10	1	region (0:'Japan', 1:'International')
	0x11	1	version
	0x12	2	ROM checksum
	0x14	4	4 bytes at 0x9C001; only tested for ROM sizes > 4
	0x18	4	offset to checksum table
	0x1C	2	flags
		0010	True if colors, not metals
		000F	???
	0x1E	2	RESERVED
...	0x420ea.	checksum tables
	0x0	2ea.	replacement table entry for bank or special value
		FEFE	ignored
		FF**	fill entire bank with **
	0x100	2ea.	order banks are loaded
		8***	saveram banks
		FEFE	load RTC
	0x220	4ea.	half-bank checksums; 2 bytes for lower 0x2000, 2 bytes for upper 0x2000
		0xFEFE + sum of each byte except bytes 0x14E and 0x14F
...	var	replacement table data
	Data is Yay compressed, padded to nearest HW.
	Patch data, when present, trails compressed data.  More than one patch may be present.
		0x0	2	offset in bank; FF** ends patch data
		0x2	1	length
		0x3	var.	XOR values against original data

  Providing a filetable switches from loading the entire game before boot into progressive loading.  Bank order should match the order banks are first used to reduce stall time when unloaded data is called.  While loading there is no controller interaction, and while saving the menu is not available.
  Filetable checksum tests ensure data read from the GB cart is valid.  If bad data is read, it will attempt to reinitialize the transfer pak and reread the data a number of times.  An error won't be raised until about 16 failed tests.

  Each version of Pokemon Stadium 2 / Pocket Monsters Stadium 3 provided its own set of replacement and patch data for its regional variant Pokemon games.  Although other region tables may be provided or recognized, replacement data was not provided due to its significant filesize.
  This was the only version of Stadium to use replacement.  Previous versions only provided the order banks were loaded and their checksums.
Pocket Monsters Stadium 1 & 2
	0x0	1	bank
		8*	RAM bank
		FF	end table
	0x1	1	RESERVED (always 0)
	0x2	2	sum of each byte in lower 0x2000 or 0 if RAM
	0x4	2	sum of each byte in upper 0x2000 or 0 if RAM

Pokemon Stadium (International versions)
	0x0	2	bank
		80**	RAM bank
	0x2	2	sum of each byte in lower 0x2000; not present if RAM
	0x4	2	sum of each byte in upper 0x2000; not present if RAM

Limitations:
*) Bank 0 cannot reliably be replaced.  Header data is effectively untouchable.  It is used to set up the emulator long before it is used to determine if a checksum table with replacement data is available.
  However, you can replace every other bank of data with impunity.  You could apply a patch using replacement binaries built from prepatched data to a GB title in the transfer pak.  Colorizing patches though require data found in the header to set it into GBC mode and (probably) will not function right if at all.
*) Patch data is applied to the provided compressed replacement binary and not to GB transfered data.  Patch data cannot be used on its own.
  That limits its usefulness, but for version differences etc. it may prove useful to make multiple entries pointing to the same compressed data but providing patches that rectify the version differences.
*) When a replacement binary is used the checksum provided should match its data, not the original data.
*) Memory allocations aside, the filetable format prevents more than 128 ROM banks from being utilized.  Even when a table is not provided, one is generated internally for unregistered titles.  The hard limit for GB titles is 2MB.

